#region Copyright and Licensing Notice
// Copyright (C) 2011 Steven Bosnick
// 
// This program is open source software; you can redistribute it 
// and/or modifiy it under the terms of the Eclipse Public License,
// version 1.0.
// 
// This program is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A 
// PARTICULAR PURPOSE. See the Eclipse Public License for more
// details.
// 
// You should have received a copy of the Eclipse Public License 
// along with this program; if not, you can find a copy at
// "http://www.opensource.org/licenses/eclipse-1.0.php".
#endregion
using System;
using BitwiseOre.SharedMemory.Core;
using BitwiseOre.SharedMemory.Core.Primatives;
using NUnit.Framework;
using Moq;

namespace BitwiseOre.Tests.SharedMemory.Primatives
{
    [TestFixture]
    public sealed class BufferLayoutFixture : AssertionHelper
    {
        [Test(Description = "Checks that the Length getter retrieves the value from the lenghts array at " +
                            "the index for this buffer layout.")]
        public void LengthGetter_DelegatesToIntArrayAtIndex()
        {
            const int index = 3;
            const int value = 7;
            var lengths = new Mock<IIntArray>();
            lengths.Setup(l => l[index]).Returns(value);

            var layout = new BufferLayout(lengths.Object, index, new Mock<IByteArray>().Object);
            var result = layout.Length;

            lengths.Verify(l => l[It.Is<int>(i => i == index)],
                           "Length getter did not delgate to lengths array at the supplied index.");
            Expect(result, EqualTo(value),
                   "Length getter did not return value from lengths array indexer.");
        }

        [Test(Description = "Checks that the Length setter sets the value to the length array at the " +
                            "index for htis buffer layout.")]
        public void LengthSetter_DelegatesToLenghtsArrayAtIndex()
        {
            const int index = 3;
            const int value = 7;
            var lengths = new Mock<IIntArray>();

            var layout = new BufferLayout(lengths.Object, index, new Mock<IByteArray>().Object);
            layout.Length = value;
            
            lengths.VerifySet(l => l[index] = value,
                           "Length setter did not set correct value in the lengths array.");
        }

    }
}